<?php
/**
 * 验证码文件
 */
include_once(dirname(__file__).'/../../init.php');
header("Expires: Mon, 26 Jul 1997 05:00:00 GMT");
header("Cache-Control: no-cache, must-revalidate");
header("Pragma: no-cache");
header("Content-type: image/png");
// 标识符
$t = '';
if ( isset($_GET['t']) ){
	$t = trim($_GET['t']);
}
$len = 4;
// 长度
if ( isset($_GET['l']) ){
	$len = intval($_GET['l']);
}
if ( !$t ){
	$t = 'default';
}
if ( $len<=0 ){
	$len = 4;
}
$chars = 'ABCDEFGHIJKMNPQRSTUVWXYZabcdefghijkmnpqrstuvwxyz23456789';
$chars = str_shuffle($chars);
$verify_code = substr($chars,0,$len);
$width	= $len*9+20;;
$height	= 30;
$im = @imagecreate($width,$height);
$background_color = imagecolorallocate($im,200,200,200);
//开始填充点儿
$sum = 50;
while ($sum){
	$x = rand(0,$width);
	$y = rand(0,$height);
	$r_x = rand(1,2);
	$r_y = rand(1,2);
	$color = imagecolorallocate($im,rand(0,255),rand(0,255),rand(0,255));
	imagefilledrectangle($im,$x,$y,$x+$r_x,$y+$r_y,$color);
	$sum--;
}
//写验证码
$text_color = imagecolorallocate($im,0,0,0);
$_SESSION['verify_code'][$t] = $verify_code;
imagestring($im,5,10,5,$verify_code,$text_color);
imagepng($im);
imagedestroy($im);
?>